<?php

function press_releases_validation($form) {

//echo $form['field_press_availability']['und']['#value']; die;

//print_r($form); die;

  $stat = new set_static_variable();
  
  //Concerned dept validation
  //chk_concerned_dept($form['field_press_dept']); 
  //check_title_duplication($form['title'], $form['type']['#value'], $form['field_press_dept'], 'field_press_dept', $stat->get_nid());
  $stat->set_nid(0);

  chkbadchar($form['title']['#value'], $form['title']['#title'], 'title'); 
  chkbadchar($form['field_press_number']['und'][0]['value']['#value'], $form['field_press_number']['und'][0]['value']['#title'], 'field_press_number');
  chkbadchar($form['field_press_details']['und'][0]['value']['#value'], $form['field_press_details']['und'][0]['value']['#title'], 'field_press_details');
  chkbadchar($form['field_press_photo_caption']['und'][0]['value']['#value'], $form['field_press_photo_caption']['und'][0]['value']['#title'], 'field_press_photo_caption');
  chkbadchar($form['field_press_keywords']['und'][0]['value']['#value'], $form['field_press_keywords']['und'][0]['value']['#title'], 'field_press_keywords');
  
  // Date Validation  
    //check_scheduler_date_expire($form['scheduler_settings']['unpublish_on']['date']['#value'],'unpublish_on');
													
	check_date_expire($form['field_press_date']['und'][0]['value']['date']['#value'],$form['field_press_date']['#title']);
	
  // maximum length validation for Title and Description Field
  	maxlength_validation($form['title']['#value'], 255, $form['title']['#title'], 'title');
	
	// minimum length charcter   
  	minilength_validation($form['title']['#value'], 5, $form['title']['#title'], 'title');
  	minilength_validation($form['field_press_keywords']['und'][0]['value']['#value'], 5, $form['field_press_keywords']['und'][0]['value']['#title'],'field_press_keywords');
	minilength_validation($form['field_press_details']['und'][0]['value']['#value'], 5, $form['field_press_details']['und'][0]['value']['#title'],'field_press_details');


//District field Check
distvalidation($form['field_press_district']['und']['#value']);


 // Availability of press release
 
  url_validation($form['field_press_url']['und'][0]['value']['#value']);
  //$form_type = $form['field_press_availability'];
  
 // if ($form_type['value']['#value'] == 'OnlineAvailable') {
  	  
	 // $reference_url = $form['field_press_url']['und'][0]['value']['#value'];
	
    //if(!isURL($reference_url) && $reference_url != '') {
      //form_set_error('field_press_url', t('Not a valid URL given in %name field', array('%name' => $form['field_press_url'] ['und'][0]['value']['#title'])));    
    //}
    //elseif ($reference_url == '') {
      //form_set_error('field_press_url', t(' %name field is required', array('%name' => $form['field_press_url']['und'][0]['value']['#title'])));
    //}
 //}
 
 if ($form['field_press_availability']['und']['#value'] == '_none') { 
 
    // Validating the file size   
    //$field_obj = $form['field_act_file_upload']; 
	//$file_allowed_obj = $form_type;
	//print_r($form['field_act_file_upload']);
	
	$filename = $form['field_press_photos']['und'][0]['#file']; 
	$filename->filename;
    file_upload_validation_D7($filename->filename,$form['field_press_photos']['und']['#title']);  
  
  }
  
	if ($form['field_press_availability']['und']['#value'] == 'download') {
	// Validating the file size   
	/* $field_obj = $form['field_press_upload']; 
	$file_allowed_obj = $form['field_form_allowedfiletype'];
	file_upload_validation($field_obj, $file_allowed_obj, 'field_press_upload');  */
		
		//echo $form['field_press_number'][0]['value']['#value'];
	
		if($form['field_press_number']['und'][0]['value']['#value']==''){
		     form_set_error($field_name, t('Kindly choose the upload file '.$field_name.' field', array(
													   '%name' => $form['field_press_number']['und'][0]['value']['#value']['#title'])));
			 //form_set_error('field_press_number', t('If \'Availability of PressRelease\' is Downloadble, %name field is required', array(
													   //'%name' => $form['field_press_number']['und'][0]['value']['#value']['#title'])));
		}
		
		if($form['field_press_upload']['und'][0]['fid']['#value']=='0'){
		form_set_error('field_press_upload', t('If \'Availability of PressRelease\' is Downloadble, %name field is required', array(
													   '%name' => $form['field_press_upload']['und'][0]['fid']['#value']['#title'])));
		}
	}
	
	
	elseif ($form['field_press_availability']['und']['#value'] == ''){
	
		if($form['field_press_photos']['und'][0]['fid']['#value']=='0'){ 
		
			form_set_error('field_press_photos', t('Both \'Press Release Photos\' and  \'Avaialbility of press release\' cannot be empty. Atlease either one of the value should be Entered', array('%name' => $form['field_press_number'] ['und'][0]['value']['#value']['#title'])));
		}
	
	}

}
 

	

   // function form_presave_validation()
   




